package test02;

/**
 * 功能：
 * 作者：lijingyi
 * 日期： 15:43
 */
import javax.swing.*;
import java.awt.*;

public class RoseDrawing extends JPanel {

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D) g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        // 设置颜色
        g2d.setColor(Color.RED);

        // 画花瓣
        int[] xPoints = {150, 200, 250, 300, 250, 200};
        int[] yPoints = {100, 50, 100, 150, 200, 150};
        for (int i = 0; i < 6; i++) {
            g2d.fillOval(xPoints[i], yPoints[i], 100, 100);
        }

        // 画花心
        g2d.setColor(Color.YELLOW);
        g2d.fillOval(200, 125, 60, 60);

        // 画花茎
        g2d.setColor(Color.GREEN);
        g2d.setStroke(new BasicStroke(5));
        g2d.drawLine(230, 185, 230, 350);

        // 画叶子
        g2d.setColor(Color.GREEN.darker());
        g2d.fillOval(150, 300, 100, 50);
        g2d.fillOval(180, 340, 100, 50);
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("玫瑰花绘制");
        RoseDrawing roseDrawing = new RoseDrawing();
        frame.add(roseDrawing);
        frame.setSize(500, 500);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}